//import { BuffData } from "./BuffData";

import { EBaseAttribute, EEvent, EGeneralSkill, EPlayerType, ESkill, EWuxing } from "./Config/Enum";

import { PlayerConfig } from "./Config/PlayerConfig";

export interface IGeneralData {
    level: number;
    renown: number;
    renownToNextLevel: number
    assignedActiveSkill:EGeneralSkill;
    assignedPassiveSkill:EGeneralSkill;



}



export class GeneralData implements IGeneralData {

    level: number = 0;
    renown: number = 0;
    renownToNextLevel: number = 0;
    assignedActiveSkill: EGeneralSkill
    assignedPassiveSkill: EGeneralSkill


    isLevelUp: boolean = false; // 是否升级

    constructor() {
        Object.assign(this, {
            level: 1,
            renown:0,
            renownToNextLevel:0,
        });

        this.initExperienceSystem();

    }


        // 初始化修为系统
    initExperienceSystem() {
        this.calculateExpToNextLevel();
    }


        // 计算升级所需修为 (二次增长曲线)
    calculateExpToNextLevel() {
        // 基础修为值 * 等级^1.5
        this.renownToNextLevel = Math.floor(5000 * Math.pow(this.level, 2));
    }

        // 添加修为值
    addRenown(amount: number) {
        this.renown += amount;
        // 检查是否升级
        while (this.renown >= this.renownToNextLevel && this.level < 9) { // 假设最大9级
            this.levelUp();
        }
    }

    // 升级逻辑
    levelUp() {
        this.renown -= this.renownToNextLevel; // 扣除升级所需修为
        this.level++;
        this.isLevelUp = true; // 标记为升级状态

        // 修复：升级后重新计算下一级所需名望值
        this.calculateExpToNextLevel();


    }

    getPackage(): Partial<IGeneralData> {
        return {
            level: this.level,
            renown: this.renown,
            renownToNextLevel: this.renownToNextLevel,
            assignedActiveSkill: this.assignedActiveSkill,
            assignedPassiveSkill: this.assignedPassiveSkill,

        };
    }

    setPackage(data: Partial<IGeneralData>): void {
                console.log('GeneralData setPackage data1:', data);
        if (!data) return;


        console.log('GeneralData setPackage data:', data);
        const baseProps: (keyof IGeneralData)[] = [
            'level', 'renown', 'renownToNextLevel', 'assignedActiveSkill', 'assignedPassiveSkill'
        ];
        
        baseProps.forEach(prop => {
            if (data[prop] !== undefined) {
                (this as any)[prop] = data[prop];
            }
        });



    }
}